package cn.wolfcode.web.Interceptor;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if (handler instanceof HandlerMethod){
            Object emp = request.getSession().getAttribute("USER_IN_SESSION");
            if (emp == null){
                response.sendRedirect("/login.html");
                return false;
            }
        }
        return true;
    }
}
